{% extends "restos/resto_base.html" %}

{% comment %}
<!--
  Copyright (C) 2010 ZHENG Zhong <http://www.zhengzhong.net/>
  Created on 2010-02-10.
  $Id$
-->
{% endcomment %}

{% load friday_extra %}

{#________________________________________________________________________________________________#}

{% block html_title %} {{ resto|escape }} {% endblock %}

{#________________________________________________________________________________________________#}

{% block sidebar %}

  <!-- information ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->

  <div class="section">

    <h2>Information:</h2>

    {% if resto.geo_pt %}
      <div id="map-canvas" class="s-map"></div>
      <p><a href="#TODO">&raquo; View larger map</a></p>
      <script type="text/javascript">//<![CDATA[
        $(function() {
          friday.showMap({{ resto.geo_pt.lat }}, {{ resto.geo_pt.lon }}, "#map-canvas");
        });
      //]]></script>
    {% endif %}

    <dl>
      <dt>
        <img class="icon" src="{{ static_ }}/images/address.png" alt="Address"/>
        Address:
      </dt>
      <dd>
        {{ resto.address|escape }}<br/>
        {{ resto.city|escape }} {{ resto.post_code|default:""|escape }}
      </dd>
    </dl>

    {% if resto.route %}
      <dl>
        <dt>
          <img class="icon" src="{{ static_ }}/images/route.png" alt="Route"/>
          Route:
        </dt>
        <dd>{{ resto.route|escape }}</dd>
      </dl>
    {% endif %}

    {% if resto.tels %}
      <dl>
        <dt>
          <img class="icon" src="{{ static_ }}/images/tel.png" alt="Tel"/>
          Tel:
        </dt>
        <dd>{{ resto.tels|join:" / "|escape }}</dd>
      </dl>
    {% endif %}

    {% if resto.hours %}
      <dl>
        <dt>
          <img class="icon" src="{{ static_ }}/images/time.png" alt="Hours"/>
          Hours:
        </dt>
        <dd>
          {% for hours in resto.hours %}
            {{ hours|escape }}<br/>
          {% endfor %}
        </dd>
      </dl>
    {% endif %}

    {% if resto.places %}
      <dl>
        <dt>
          <img class="icon" src="{{ static_ }}/images/group.png" alt="Places"/>
          Places:
        </dt>
        <dd>{{ resto.places }} seats</dd>
      </dl>
    {% endif %}

    <dl>
      <dt>
        <img class="icon" src="{{ static_ }}/images/category.png" alt="Category"/>
        Category:
      </dt>
      <dd>
        <a href="{% url friday.view_restos_by_category category=resto.category %}">
          {{ resto.get_category_display }}
        </a>
      </dd>
    </dl>

  </div>

  <!-- tags ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->

  <div class="section">

    <h2>Tags:</h2>

    <div id="load-resto-tags">
      <div class="ajax-loader">
        <img src="{{ static_ }}/images/ajax_loader.gif" alt="Loading"/>
        Loading tags...
      </div>
      <div class="ajax-error hidden">
        <img src="{{ static_ }}/images/error.png" alt="Error"/>
        Failed to load tags.
      </div>
    </div>

    <script type="text/javascript">//<![CDATA[
      $(function() {
        $("#load-resto-tags").load(
          "{% url friday.view_resto_tags resto_id=resto.id %}",
          function(response, textStatus) {
            if (textStatus == "error") {
              $("#load-resto-tags .ajax-loader").hide();
              $("#load-resto-tags .ajax-error").show();
            }
          }
        );
      });
    //]]></script>

  </div>

  <!-- submitter and updater ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->

  <div class="section">

    {% ifnotequal resto.submitter resto.updater %}

      <div class="user-box">
        <div class="user-avatar">
          <a href="{% url friday.view_profile username=resto.submitter.username %}">
            <img src="{% url friday.view_avatar username=resto.submitter.username %}" alt="{{ resto.submitter|escape }}"/>
          </a>
        </div>
        <div class="user-info">
          Added on {{ resto.submit_date|date:"d N Y" }}<br/>
          by <a href="{% url friday.view_profile username=resto.submitter.username %}">{{ resto.submitter|escape }}</a>
        </div>
        <div class="clear"></div>
      </div>

    {% endifnotequal %}

    <div class="user-box">
      <div class="user-avatar">
        <a href="{% url friday.view_profile username=resto.updater.username %}">
          <img src="{% url friday.view_avatar username=resto.updater.username %}" alt="{{ resto.updater|escape }}"/>
        </a>
      </div>
      <div class="user-info">
        Updated on {{ resto.submit_date|date:"d N Y" }}<br/>
        by <a href="{% url friday.view_profile username=resto.updater.username %}">{{ resto.updater|escape }}</a>
      </div>
      <div class="clear"></div>
    </div>

  </div>

  <!-- administration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->

  {% if resto_access.can_edit or resto_access.can_delete %}
    <div class="section">
      <h2>Administration:</h2>
      <ul>
        {% if resto_access.can_edit %}
          <li><a href="{% url friday.edit_resto resto_id=resto.id %}">Edit resto information</a></li>
          <li><a href="{% url friday.recommend_dish resto_id=resto.id %}">Recommend a dish</a></li>
        {% endif %}
        {% if resto_access.can_delete %}
          <li><a href="{% url friday.delete_resto resto_id=resto.id %}">Delete this resto</a></li>
        {% endif %}
      </ul>
    </div>
  {% endif %}

{% endblock %}

{#________________________________________________________________________________________________#}

{% block content %}

  <div class="section">
    <h1>{{ resto.name|escape }}</h1>
    <h5>{{ resto.address|escape }}, {{ resto.city|escape }}  {{ resto.post_code|default:""|escape }}</h5>
  </div>

  {% if resto.description %}
    <div class="section">
      <h2>Description:</h2>
      {{ resto.description|escape|linebreaks }}
    </div>
  {% endif %}

  {% include "restos/common/resto_faves.html" %}

  <!-- resto recommended dishes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->

  {% if resto.dishes %}
    <div class="section">
      <h2>Recommended Dishes:</h2>
      {% for dish in resto.dishes %}
        {% include "restos/common/dish.html" %}
      {% endfor %}
    </div>
  {% endif %}

  <!-- resto tabs ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->

  <div class="section">
    <div id="resto-tabs">
      <ul>
        <li><a href="{% url friday.view_comments ref_type=resto.model_name ref_pk=resto.pk %}">Comments</a></li>
      </ul>
    </div>
    <script type="text/javascript">//<![CDATA[
      $(function() {
        $("#resto-tabs").tabs({
          ajaxOptions: {
            error: function(xhr, status, index, anchor) {
              if (index == 0) {
                target = "comments";
              } else {
                target = "unknown objects";
              }
              $(anchor.hash).html("Failed to load " + target + " via AJAX: server error.");
            }
          }
        });
      });
    //]]></script>
  </div>

{% endblock %}{# content #}



